import type { Request, Response } from "express";
import { handleError, handleSucceed } from "@/utils/stateHandle";
import { JWT } from "@/utils/JWT";

export const login = (req: Request, res: Response) => {
  const { account, password } = req.body;
  if (account === "admin" && password === "123456") {
    // 1小时 时分秒
    const token = JWT.generate({ account }, 1 * 60 * 60 + "s");
    // const token = JWT.generate({ account }, "5s");
    handleSucceed(res, { token }, "登录成功");
  } else {
    handleError(res, "账号或密码错误", 201);
  }
};
